<template>
	<uni-loading v-if="loading"></uni-loading>
	<view class="body" v-else>
		<!--  列表  -->
		<template v-if="purchaseList && purchaseList.length > 0">
			<template v-for="item in purchaseList">
				<view class="panel bottomBorder" @click="goto(item)">
					<view class="panel_title">
						<view class="panel_title_left">{{ item.billNo }}</view>
					</view>
					<view class="panel_content">
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">创建人：</view>
								<view class="panel_content_row_item_value">{{ item.createUserName }}</view>
							</view>
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">仓库：</view>
								<view class="panel_content_row_item_value">{{ item.stockName }}</view>
							</view>
						</view>
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">箱数：</view>
								<view class="panel_content_row_item_value">{{ item.boxCount }}</view>
							</view>
							<view class="panel_content_row_item">
							    <view class="panel_content_row_item_title">总重：</view>
							    <view class="panel_content_row_item_value">{{ item.count }}{{ item.unit }}
							    </view>
							</view>
						</view>
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">创建时间：</view>
								<view class="panel_content_row_item_value">{{ item.createTime }}</view>
							</view>
						</view>
					</view>
				</view>
			</template>
		</template>
		<uni-empty-info v-else label="暂无入库订单"></uni-empty-info>
	</view>
</template>
<script>
	import uniLoading from "../../vBase/components/uni-loading/uni-loading"
	import uniEmptyInfo from "../../vBase/components/uni-empty-info/uni-empty-info"
	import dayjs from 'dayjs'

	export default {
		components: {
			uniLoading,
			uniEmptyInfo,
		},
		data() {
			return {
				loading: false,
				purchaseList: [],
				orderNo: "",
				stockList: []
			}
		},
		async onShow() {
			if (this.orderNo) {
				this.initData()	
			}
		},
		async onLoad(e) {
			await this.getStockList()
			if (e.orderNo) this.orderNo = e.orderNo
			this.initData()
		},
		methods: {

			/** 查询仓库*/
			async getStockList() {
				this.loading = true;
				try {
					let {
						res,
						stockList = []
					} = await this.$api.getCustomerStock();
					if (!res) return;
					this.stockList = stockList;
				} finally {
					this.loading = false;
				}
			},

			/** 初始化数据 */
			initData() {
				this.pageConfig = {
					pageIndex: 0,
					pageSize: 20,
					bottomEnd: false,
					bottomLoading: true
				}
				this.getPurchaseList()
			},

			/**
			 *
			 */
			async openDetail(material) {

			},

			/** 获取数据 */
			async getPurchaseList() {
				let {
					res,
					data = []
				} = await this.$api.getCreatedBcPurinList({
					orderNo: this.orderNo,
				});
				if (!res) return;
				this.purchaseList = data.map(v => ({
					...v,
					createTime: dayjs(v.createTime).format("YYYY-MM-DD HH:mm:ss"),
					stockName: this.stockList.find(item => item.stockNo === v.stockNo).stockName
				}));
				this.loading = false;
				uni.stopPullDownRefresh();
			},

			/**
			 * 下拉刷新数据
			 */
			onPullDownRefresh() {
				this.initData()
			},

			/**
			 * 跳转值编辑页面
			 * @param {Object} e
			 */
			goto(e) {
				this.$navigateTo(`/pages/purchase/packageOrderEdit?billNo=${e.billNo}&orderNo=${e.orderNo}`)
			}
		}
	}
</script>
<style lang="scss" scoped>
	@import "../../static/css/common";
</style>
